package com.capgemini.diabeo.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.capgemini.diabeo.model.Dish;
import com.capgemini.diabeo.model.Menu;
import com.capgemini.diabeo.view.DishItemView;
import com.capgemini.diabeo.view.DishItemView_;
import com.googlecode.androidannotations.annotations.AfterInject;
import com.googlecode.androidannotations.annotations.EBean;
import com.googlecode.androidannotations.annotations.RootContext;

@EBean
public class DishListAdapter extends BaseAdapter {

	private List<Dish> dishes;

	@RootContext
	static Context context;

	private boolean hasAddButton = true;

	@AfterInject
	public void afterInject() {
		dishes = new ArrayList<Dish>();
	}

	public void setDishList(List<Dish> dishes) {
		this.dishes = dishes;
	}

	public void removeAddButton() {
		hasAddButton = false;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		DishItemView dishItemView;
		if (convertView == null) {
			dishItemView = DishItemView_.build(context);
		} else {
			dishItemView = (DishItemView) convertView;
		}
		dishItemView.bind(getItem(position), hasAddButton);

		return dishItemView;
	}

	@Override
	public int getCount() {
		return dishes.size();
	}

	@Override
	public Dish getItem(int position) {
		return dishes.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	public List<Dish> getDishList() {
		// TODO Auto-generated method stub
		return this.dishes;
	}
}